home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume12 / cnews / part05 < prev    next >
Encoding:
Internet Message Format  |  1987-10-21  |  52.8 KB

  1. Subject:  v12i030:  C News alpha release, Part05/14
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rs@uunet.UU.NET
  5.  
  6. Submitted-by: utzoo!henry (Henry Spencer)
  7. Posting-number: Volume 12, Issue 30
  8. Archive-name: cnews/part05
  9.  
  10.  
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 5 (of 14)."
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'README.FIRST' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'README.FIRST'\"
  22. else
  23. echo shar: Extracting \"'README.FIRST'\" \(2991 characters\)
  24. sed "s/^X//" >'README.FIRST' <<'END_OF_FILE'
  25. XFor a number of reasons, notably continued slow progress and strong demand,
  26. XGeoff and I have decided to release an "official alpha test" C news widely.
  27. X
  28. XThis IS NOT the definitive release.  As the word "alpha" implies, it
  29. Xis not even beta test.  This release is NOT nicely packaged, it is NOT
  30. Xbug-free, it does NOT have the full desired functionality (for example,
  31. Xit doesn't have moderated-group security yet), it undoubtedly has some
  32. Xportability and compatibility problems, it is not properly documented,
  33. Xand it WILL be superseded by a later version in a conversion that is
  34. XNOT guaranteed to be painless.  In other words, use at your own risk.
  35. XIt is essentially our current working version.
  36. X
  37. XIf you don't have time to explore its idiosyncrasies and babysit its
  38. Xproblems, you should not even try to put it up.  Note the redistribution
  39. Xrestrictions in the copyright notices, by the way -- these are meant solely
  40. Xto keep this alpha release under control, and will not be present in the
  41. Xfinal release.
  42. X
  43. XWe strongly suggest, however, that anyone currently running one of our
  44. Xold informal pre-alpha releases upgrade to this one.  It will be no harder
  45. Xto install than the pre-alpha one was, and it fixes a near-endless list
  46. Xof bugs, bad behaviors, and gaps in functionality.
  47. X
  48. X
  49. XWe know that this release has problems of various kinds.  We intend to fix
  50. Xthem.  We are interested in hearing about the more subtle ones.  We DO NOT
  51. Xwant to see 2000 lines of diff listing!  Why?  First, because our source
  52. Xwill have changed by the time your diffs arrive.  Second, because there is
  53. Xa good chance that we are already aware of the problem you've found; we
  54. Xmay even have fixed it already.  Send us a SHORT description of what you've
  55. Xfound and what (if anything) you've done about it; if we want diffs, we
  56. Xwill certainly ask.  The same applies to changes and improvements.
  57. X
  58. XIf you want us to consider changes/fixes/etc, send them to us, don't just
  59. Xpost them to the net.  We reserve the right to ignore all posted changes
  60. Xand "improvements" when preparing the definitive release.  For at least the
  61. Xduration of the alpha release, only postings from us are officially part
  62. Xof C news.
  63. X
  64. XReaders should not assume that comments saying "to do" in the source
  65. Xor suggestively-named files reflect our current thinking on what needs
  66. Xdoing or should be done.
  67. X
  68. XThe place to send comments, complaints, problem reports, etc. is NOT to
  69. XGeoff or me personally, but to:
  70. X
  71. X    utzoo!cnews-alpha
  72. X
  73. XUtzoo connects to half the known universe (well, not quite, but try via
  74. Xattunix, allegra, ihnp4, decvax, pyramid, floyd, hoptoad, kitty, linus,
  75. Xmnetor, utai, utcsri, or watmath).  Sorry, we don't have a direct uunet
  76. Xhookup at present.  Nor are we on the Arpa internet, although those of
  77. Xyou with MX-comprehending mailers can try cnews-alpha@utzoo.toronto.edu
  78. X(it is supposed to work).  If you are off in the wonderful (?) world of
  79. XBitnet, try cnews-alpha@utzoo.utoronto or words to that effect.
  80. X
  81. X                    Geoff Collyer
  82. X                    Henry Spencer
  83. END_OF_FILE
  84. if test 2991 -ne `wc -c <'README.FIRST'`; then
  85.     echo shar: \"'README.FIRST'\" unpacked with wrong size!
  86. fi
  87. # end of 'README.FIRST'
  88. fi
  89. if test -f 'batch/README' -a "${1}" != "-c" ; then 
  90.   echo shar: Will not clobber existing file \"'batch/README'\"
  91. else
  92. echo shar: Extracting \"'batch/README'\" \(2263 characters\)
  93. sed "s/^X//" >'batch/README' <<'END_OF_FILE'
  94. XThis is the C News batching subsystem.  To install, inspect/change the
  95. Xconfiguration stuff at the top of the Makefile, and then "make install".
  96. X
  97. XThe only thing in here that even needs compiling is batchmake.c; it needs
  98. Xnone of the news include files etc., although it may need some of the
  99. Xstuff in ../libc if your system does not have getopt(), error(), or the
  100. Xfull set of string functions.  All other programs in here are shell files.
  101. X
  102. Xnewsbatch.8.p is a prototype manual page; the Makefile knows how to turn
  103. Xit into a real one.  teststuff is a shell archive of test files; again,
  104. Xthe Makefile knows what to do with them.
  105. X
  106. XThe sys file must direct the filenames to be batched for system xxx into
  107. Xthe file $NEWSCTL/batch/b.xxx/togo .  Then arrangements must be made
  108. Xfor sendbatches to be run periodically. 
  109. X
  110. XYou will need to revise queuelen and roomfor to work on your system --
  111. Xtheir innards are system-dependent.  You may want to change the policies
  112. Xdictated by queuemax, roomfor, and batchsize.  You might also want to
  113. Xrevise batchmunch and batchxmit, although the defaults should work fairly
  114. Xwell in ordinary situations on orthodox Unixes.  Note that one can override
  115. Xthe defaults for specific feeds by placing non-default versions in suitable
  116. Xplaces; see the manual page.  MAKE SURE YOU MAKE THEM EXECUTABLE.
  117. X
  118. XThe batchmunch and batchxmit files are set up for 2.11 compatibility, using
  119. Xthe stupid "#! cunbatch" format; to just send the stuff compressed without
  120. Xthe silly uncompressed header, take the 'echo' out of batchmunch.  (If you
  121. Xare talking to an old system, you may also need to change 'rnews' in
  122. Xbatchxmit to 'cunbatch'.)
  123. X
  124. XNote that because sendbatches suspends batching when space gets low or
  125. Xqueues get long, outgoing news transmission can quietly stop if you're
  126. Xusing a lot of disk for other things.  It is HIGHLY desirable to monitor
  127. Xthe batcher backlogs, perhaps by a daily run of something resembling:
  128. X
  129. X    mail yourself </usr/lib/news/batchlog
  130. X
  131. XNote that the test procedure indicated at the end of "make install" checks
  132. Xout sendbatches, batchmake, and batchprep in a simple way, but does not
  133. Xtest the other stuff much.
  134. X
  135. XOh yes:  if your shell is too old to understand comments begun with #, you
  136. Xare in trouble and have a lot of editing to do...
  137. END_OF_FILE
  138. if test 2263 -ne `wc -c <'batch/README'`; then
  139.     echo shar: \"'batch/README'\" unpacked with wrong size!
  140. fi
  141. # end of 'batch/README'
  142. fi
  143. if test -f 'batch/batchmake.c' -a "${1}" != "-c" ; then 
  144.   echo shar: Will not clobber existing file \"'batch/batchmake.c'\"
  145. else
  146. echo shar: Extracting \"'batch/batchmake.c'\" \(3008 characters\)
  147. sed "s/^X//" >'batch/batchmake.c' <<'END_OF_FILE'
  148. X/*
  149. X * batchmake - send a bunch of news articles as an unbatch script
  150. X *
  151. X * Usage: batchmake [-d dir] listfile
  152. X *
  153. X *    where listfile is a file containing a list, one per line, of
  154. X *    full pathnames of files containing articles.  Only the first
  155. X *    field of each line is looked at, so there can be more if needed
  156. X *    for other things.
  157. X *
  158. X *    The -d option specifies a directory where most articles are
  159. X *    likely to be; the program chdirs there to speed things up.
  160. X */
  161. X
  162. X#include <stdio.h>
  163. X#include <string.h>
  164. X#include <signal.h>
  165. X#include <sys/types.h>
  166. X#include <sys/stat.h>
  167. X
  168. X#ifndef READSIZE
  169. X#define READSIZE 8192    /* allows for even 4.2 worst case file systems */
  170. X#endif
  171. Xchar buffer[READSIZE];
  172. X
  173. Xchar *progname;
  174. X
  175. Xchar *dir = NULL;        /* NULL means don't bother chdiring. */
  176. Xint dirlen;            /* strlen(dir) */
  177. Xint debug = 0;            /* Debugging? */
  178. X
  179. Xmain(argc, argv)
  180. Xint argc;
  181. Xchar *argv[];
  182. X{
  183. X    int c;
  184. X    int errflg = 0;
  185. X    extern int optind;
  186. X    extern char *optarg;
  187. X    register FILE *list;
  188. X    char article[BUFSIZ];
  189. X    int ret;
  190. X
  191. X    progname = argv[0];
  192. X    while ((c = getopt(argc, argv, "d:x")) != EOF)
  193. X        switch (c) {
  194. X        case 'd':    /* Directory containing many articles. */
  195. X            dir = optarg;
  196. X            dirlen = strlen(dir);
  197. X            break;
  198. X        case 'x':    /* Debugging. */
  199. X            debug++;
  200. X            break;
  201. X        case '?':
  202. X        default:
  203. X            errflg++;
  204. X            break;
  205. X        }
  206. X    if (errflg || optind != argc-1) {
  207. X        (void) fprintf(stderr,
  208. X            "Usage: batchmake [-d dir] listfile\n");
  209. X        exit(2);
  210. X    }
  211. X
  212. X    if (access(argv[optind], 0) < 0)
  213. X        error("can't find `%s'", argv[optind]);
  214. X    if (access(argv[optind], 04|02) < 0)
  215. X        error("inadequate permissions on `%s'", argv[optind]);
  216. X    list = fopen(argv[optind], "r");
  217. X    if (list == NULL)
  218. X        error("unable to open `%s'", argv[optind]);
  219. X
  220. X    if (dir != NULL && access(dir, 04|01) < 0)
  221. X        error("inaccessible directory: `%s'", dir);
  222. X    if (dir != NULL)
  223. X        if (chdir(dir) < 0)
  224. X            error("can't chdir to `%s'", dir);
  225. X
  226. X    while (fgets(article, sizeof article, list) != NULL)
  227. X        process(article);
  228. X
  229. X    exit(0);
  230. X}
  231. X
  232. X/*
  233. X - process - process an article
  234. X */
  235. Xprocess(article)
  236. Xchar *article;
  237. X{
  238. X    char *p;
  239. X    register int artfile;
  240. X    register int count;
  241. X    struct stat sbuf;
  242. X
  243. X    *(article + strcspn(article, "\n\t ")) = '\0';
  244. X    if (dir != NULL && strncmp(article, dir, dirlen) == 0 &&
  245. X            article[dirlen] == '/')
  246. X        p = article+dirlen+1;
  247. X    else
  248. X        p = article;
  249. X
  250. X    artfile = open(p, 0);
  251. X    if (artfile < 0) {
  252. X        /*
  253. X         * Can't read the article.  This isn't necessarily a
  254. X         * disaster, since things like cancellations will do
  255. X         * this.  Mumble and carry on.
  256. X         */
  257. X        if (debug)
  258. X            warning("can't find `%s'", p);
  259. X        return;
  260. X    }
  261. X
  262. X    if (fstat(artfile, &sbuf) < 0)
  263. X        error("internal disaster, can't fstat", "");
  264. X    if ((sbuf.st_mode&S_IFMT) != S_IFREG) {
  265. X        close(artfile);
  266. X        return;        /* Don't try to batch directories etc. */
  267. X    }
  268. X
  269. X    (void) printf("#! rnews %ld\n", sbuf.st_size);
  270. X    fflush(stdout);
  271. X
  272. X    while ((count = read(artfile, buffer, sizeof buffer)) > 0)
  273. X        if (write(1, buffer, count) != count)
  274. X            error("write failure in `%s'", article);
  275. X    if (count < 0)
  276. X        error("read failure in `%s'", article);
  277. X
  278. X    (void) close(artfile);
  279. X}
  280. END_OF_FILE
  281. if test 3008 -ne `wc -c <'batch/batchmake.c'`; then
  282.     echo shar: \"'batch/batchmake.c'\" unpacked with wrong size!
  283. fi
  284. # end of 'batch/batchmake.c'
  285. fi
  286. if test -f 'expire/Makefile' -a "${1}" != "-c" ; then 
  287.   echo shar: Will not clobber existing file \"'expire/Makefile'\"
  288. else
  289. echo shar: Extracting \"'expire/Makefile'\" \(2199 characters\)
  290. sed "s/^X//" >'expire/Makefile' <<'END_OF_FILE'
  291. X# If you don't have a dirent.h header file, add -I. to CFLAGS and see README.
  292. XDEFINES = -DEXP
  293. XCFLAGS = -O $(DEFINES) -I../include
  294. XLINTFLAGS = $(DEFINES) -Dvoid=int
  295. XLDFLAGS = -i
  296. XOBJS=expire.o
  297. XLIBS= ../libcnews/libcnews.a ../libc/*.a
  298. XD = NEWSARTS=`pwd` NEWSCTL=`pwd`
  299. XTHEM = expire histconv histdups histinfo histslash lowest mkdbm mkhistory \
  300. X    olddate oldfile upact xargs
  301. XNEWSBIN = /usr/lib/newsbin
  302. X
  303. Xexpire: $(OBJS)
  304. X    $(CC) $(LDFLAGS) $(OBJS) $(LIBS) -ldbm -o $@
  305. X
  306. Xhistinfo: histinfo.o
  307. X    $(CC) $(LDFLAGS) histinfo.o $(LIBS) -o $@
  308. X
  309. Xxargs:    xargs.o
  310. X    $(CC) $(LDFLAGS) xargs.o -o $@
  311. X
  312. Xlowest:    lowest.o
  313. X    $(CC) $(LDFLAGS) lowest.o -o $@
  314. X
  315. Xlowest.o:    lowest.c
  316. X    @echo 'If this cannot find dirent.h, see README for instructions.'
  317. X    $(CC) $(CFLAGS) -c lowest.c
  318. X
  319. Xlint:
  320. X    lint -ha $(LINTFLAGS) expire.c -ldbm
  321. X
  322. Xtidy:
  323. X    rm -f junk history history.pag history.dir history.o active
  324. X    rm -f history.n* mon.out testctl lowest oldfile xargs
  325. X    rm -f active.old active.new
  326. X    rm -rf ns mod unmod arch
  327. X
  328. Xclean:    tidy
  329. X    rm -f *.o expire olddate histslash mkdbm histinfo
  330. X
  331. Xolddate:    olddate.o
  332. X    $(CC) $(LDFLAGS) olddate.o $(LIBS) -o $@
  333. X
  334. Xoldfile:    oldfile.o
  335. X    $(CC) $(LDFLAGS) oldfile.o $(LIBS) -o $@
  336. X
  337. Xhistslash:    histslash.o
  338. X    $(CC) $(LDFLAGS) histslash.o $(LIBS) -o $@
  339. X
  340. Xmkdbm:    mkdbm.o
  341. X    $(CC) $(LDFLAGS) mkdbm.o $(LIBS) -ldbm -o $@
  342. X
  343. Xr:    testctl mod unmod history active ns arch expire
  344. X    NEWSARTS=`pwd`/ns NEWSCTL=`pwd` NEWSBIN=`pwd`/.. expire -a `pwd`/arch -p testctl
  345. X
  346. Xtestctl:    testctl.p
  347. X    sed "s;X;`pwd`;g" testctl.p >$@
  348. X
  349. Xmod:
  350. X    rm -rf mod
  351. X    mkdir mod
  352. X
  353. Xunmod:
  354. X    rm -rf unmod
  355. X    mkdir unmod
  356. X
  357. Xarch:
  358. X    rm -rf arch
  359. X    mkdir arch
  360. X
  361. Xhistory:    ns histinfo histslash xargs mkdbm
  362. X    NEWSARTS=`pwd`/ns NEWSCTL=`pwd` NEWSBIN=`pwd`/.. mkhistory >$@
  363. X    mkdbm <$@
  364. X    mv it.pag $@.pag
  365. X    mv it.dir $@.dir
  366. X    rm -f ns/mon.out
  367. X    @echo `find ns -type f -print | wc -l` articles in ns
  368. X    @echo `egrep '^body$$' ns.p | wc -l` should be there
  369. X    @echo `wc -l history` lines in history
  370. X    @echo all three of those numbers should be the same!
  371. X    touch history
  372. X
  373. Xactive:    active.p
  374. X    cp active.p $@
  375. X
  376. Xns:    ns.p oldfile olddate
  377. X    rm -rf ns
  378. X    ns.p
  379. X
  380. Xtryup:    upact ns active lowest
  381. X    NEWSARTS=`pwd`/ns NEWSCTL=`pwd` NEWSBIN=`pwd`/.. sh -x upact
  382. X
  383. Xinstall:    $(THEM)
  384. X    mkdir $(NEWSBIN)/expire
  385. X    cp $(THEM) $(NEWSBIN)/expire
  386. END_OF_FILE
  387. if test 2199 -ne `wc -c <'expire/Makefile'`; then
  388.     echo shar: \"'expire/Makefile'\" unpacked with wrong size!
  389. fi
  390. # end of 'expire/Makefile'
  391. fi
  392. if test -f 'expire/README' -a "${1}" != "-c" ; then 
  393.   echo shar: Will not clobber existing file \"'expire/README'\"
  394. else
  395. echo shar: Extracting \"'expire/README'\" \(2324 characters\)
  396. sed "s/^X//" >'expire/README' <<'END_OF_FILE'
  397. Xexpire is the biggie here.  See manual page.
  398. X
  399. XFor those of you running 2.10.2 or later, expire does not update the
  400. X"oldest" field in the active file.  This is done by upact.  Run it now
  401. Xand then, say once a week.  lowest is part of upact.
  402. X
  403. Xmkhistory will produce, on its standard output, a rebuilt history file
  404. Xreflecting the actual /usr/spool/news contents.
  405. X
  406. Xmkdbm rebuilds the dbm files for a history file.  History file comes in
  407. Xon stdin, dbm files are created as it.pag and it.dir.
  408. X
  409. Xhistconv will convert B history files to C format, in a simplistic
  410. Xway; it ignores the possibility of files with explicit expiry dates.  If
  411. Xthis isn't satisfactory, mkhistory is your only recourse.
  412. X
  413. Xhistdups, histinfo, and histslash are parts of mkhistory.
  414. X
  415. Xolddate and oldfile are auxiliary programs for testing expire.
  416. X
  417. XThe .p files are for testing expire.  Test by saying "make r"; see
  418. Xthe Makefile.  One wart is that the results of the tests have to be
  419. Xchecked by hand -- there is no automatic comparison against the right
  420. Xanswers.
  421. X
  422. XYou should put something like "rm -f /usr/lib/news/history.n*" in your
  423. X/etc/rc, since files by that name will be left around if your system
  424. Xcrashes in the middle of an expire, and expire will balk at running if
  425. Xthey are present -- expire is quite paranoid about proceeding if there
  426. Xappears to be something seriously wrong.
  427. X
  428. XSeveral things here assume that there are no entirely-numeric directory
  429. Xnames in the article tree.
  430. X
  431. XPortability notes:
  432. X
  433. XYou'll need getopt(3), a full string(3) (strspn, strtok, etc.), and POSIX-
  434. Xcompatible directory functions.  See libc.  
  435. X
  436. XYou'll need dbm or some substitute [see inews/vers/uglix/dbm.c].
  437. X
  438. XThe getdate() routine supplied here wants a V7-style ftime() structure
  439. Xfor information on time zone etc.  If you haven't got ftime(), you'll
  440. Xhave to fudge this somehow.
  441. X
  442. XYou'll need xargs(1) for mkhistory; note that one is supplied just in case.
  443. X
  444. XA specific problem of directory functions is that since Berkeley botched
  445. Xthe name of the header file for them, there is no entirely standard place
  446. Xfor it.  This stuff assumes that it is available as <dirent.h>, as per POSIX;
  447. Xif this is not correct, you'll have to add -I. to CFLAGS and make a file
  448. X"dirent.h" containing something like "#include <whatever_the_name_is.h>".
  449. XYou may also need to add "#define dirent direct".
  450. END_OF_FILE
  451. if test 2324 -ne `wc -c <'expire/README'`; then
  452.     echo shar: \"'expire/README'\" unpacked with wrong size!
  453. fi
  454. # end of 'expire/README'
  455. fi
  456. if test -f 'expire/histinfo.c' -a "${1}" != "-c" ; then 
  457.   echo shar: Will not clobber existing file \"'expire/histinfo.c'\"
  458. else
  459. echo shar: Extracting \"'expire/histinfo.c'\" \(2487 characters\)
  460. sed "s/^X//" >'expire/histinfo.c' <<'END_OF_FILE'
  461. X/*
  462. X * histinfo - print history file lines for the named articles
  463. X */
  464. X
  465. X#include <stdio.h>
  466. X#include <sys/types.h>
  467. X#include <sys/stat.h>        /* for modified time (date received) */
  468. X#include "newspaths.h"
  469. X
  470. X#define MAXLINE 1024
  471. X#define STRLEN(s) (sizeof(s) - 1)    /* s must be a char array */
  472. X
  473. Xchar *progname;
  474. Xint debug;
  475. X
  476. XFILE *efopen();
  477. X
  478. Xchar *spdir;
  479. Xint spdirlen;
  480. X
  481. X/*
  482. X * main - parse arguments and handle options
  483. X */
  484. Xmain(argc, argv)
  485. Xint argc;
  486. Xchar *argv[];
  487. X{
  488. X    int c;
  489. X    int errflg = 0;
  490. X    FILE *in;
  491. X    extern int optind;
  492. X    extern char *optarg;
  493. X
  494. X    progname = argv[0];
  495. X    while ((c = getopt(argc, argv, "d")) != EOF)
  496. X        switch (c) {
  497. X        case 'd':
  498. X            ++debug;
  499. X            break;
  500. X        default:
  501. X            errflg++;
  502. X            break;
  503. X        }
  504. X    if (errflg) {
  505. X        (void) fprintf(stderr, "usage: %s [-d]\n", progname);
  506. X        exit(2);
  507. X    }
  508. X
  509. X    spdir = spoolfile((char *)NULL);
  510. X    spdirlen = strlen(spdir);
  511. X    
  512. X    if (optind == argc)
  513. X        process(stdin, "stdin");
  514. X    else
  515. X        for (; optind < argc; optind++) {
  516. X            in = efopen(argv[optind], "r");
  517. X            process(in, argv[optind]);
  518. X            (void) fclose(in);
  519. X        }
  520. X    exit(0);
  521. X}
  522. X
  523. X/*
  524. X * process - process input file
  525. X */
  526. Xprocess(in, inname)
  527. XFILE *in;
  528. Xchar *inname;
  529. X{
  530. X    char *nl, *files;
  531. X    char line[MAXLINE], msgid[MAXLINE], expiry[MAXLINE];
  532. X    char datercv[30];
  533. X    struct stat statb;
  534. X    static char msgidnm[] =  "Message-ID: ";
  535. X    static char expnm[] =    "Expires: ";
  536. X    char *rindex(), *strcpy();
  537. X
  538. X    /* set defaults */
  539. X    (void) strcpy(expiry, "-");
  540. X    (void) strcpy(msgid, "<swill@trash>");
  541. X
  542. X    /* read until EOF or blank line (end of headers) */
  543. X    while (fgets(line, sizeof line, in) != NULL && strcmp(line, "\n") != 0) {
  544. X        if ((nl = rindex(line, '\n')) != NULL)
  545. X            *nl = '\0';            /* trim newline */
  546. X        if (strncmp(line, msgidnm, STRLEN(msgidnm)) == 0)
  547. X            (void) strcpy(msgid, line+STRLEN(msgidnm));
  548. X        else if (strncmp(line, expnm, STRLEN(expnm)) == 0)
  549. X            (void) strcpy(expiry, line+STRLEN(expnm));
  550. X    }
  551. X
  552. X    /* generate the file name */
  553. X    files = inname;
  554. X    if (strncmp(files, spdir, spdirlen) == 0 &&
  555. X        files[spdirlen] == '/')
  556. X        files += spdirlen + 1;    /* skip spool dir. & slash */
  557. X
  558. X    /* generate the date received */
  559. X    (void) fstat(fileno(in), &statb);
  560. X    (void) sprintf(datercv, "%ld", statb.st_mtime);
  561. X
  562. X    /* whomp out the history line */
  563. X    (void) fputs(msgid, stdout);
  564. X    (void) putchar('\t');
  565. X    (void) fputs(datercv, stdout);
  566. X    (void) putchar('~');
  567. X    (void) fputs(expiry, stdout);
  568. X    (void) putchar('\t');
  569. X    (void) fputs(files, stdout);
  570. X    (void) putchar('\n');
  571. X    (void) fflush(stdout);
  572. X}
  573. X
  574. X/*
  575. X * unprivileged - no-op to keep pathname stuff happy
  576. X */
  577. Xvoid
  578. Xunprivileged()
  579. X{
  580. X}
  581. END_OF_FILE
  582. if test 2487 -ne `wc -c <'expire/histinfo.c'`; then
  583.     echo shar: \"'expire/histinfo.c'\" unpacked with wrong size!
  584. fi
  585. # end of 'expire/histinfo.c'
  586. fi
  587. if test -f 'include/news.h' -a "${1}" != "-c" ; then 
  588.   echo shar: Will not clobber existing file \"'include/news.h'\"
  589. else
  590. echo shar: Extracting \"'include/news.h'\" \(2826 characters\)
  591. sed "s/^X//" >'include/news.h' <<'END_OF_FILE'
  592. X/*
  593. X * definitions unique to news
  594. X */
  595. X
  596. X#define MAXLINE 512
  597. X#define MAXFILE 100        /* maximum file name length */
  598. X#define MAXCOMP 14        /* maximum file name component length */
  599. X#define MAXHOST 64
  600. X#define ARTNUMWIDTH 5        /* article-number width */
  601. X
  602. X#define SPOOLTMP ".tmpXXXXXX"
  603. X#ifndef STDPATH
  604. X#define STDPATH "/bin:/usr/bin:/usr/ucb"    /* standard search path */
  605. X#endif
  606. X
  607. X/* status bits */
  608. X#define ST_OKAY        0    /* nothing wrong */
  609. X#define ST_SHORT    (1<<1)    /* article shorter than byte count; truncated? */
  610. X#define ST_ACCESS    (1<<2)    /* no access permission */
  611. X#define ST_NUKED    (1<<3)    /* article was deliberately dropped - OK */
  612. X#define ST_DROPPED    (1<<4)    /* article was accidentally dropped */
  613. X#define ST_DISKFULL    (1<<5)    /* disk full - give up */
  614. X
  615. X/* newsgroup specific definitions */
  616. X#define NGSEP ','        /* separates groups */
  617. X#define NGNEG '!'        /* preceding a pattern, negates it */
  618. X#define NGDELIM '.'        /* within a group */
  619. X#define FNDELIM '/'        /* within a group, on disk */
  620. X#define SFNDELIM "/"        /* string of FNDELIM */
  621. X
  622. X#define max(a,b) ((a) > (b)? (a): (b))
  623. X#define min(a,b) ((a) < (b)? (a): (b))
  624. X#define iswhite(c) ((c) == ' ' || (c) == '\t')
  625. X/* STREQ is an optimised strcmp(a,b)==0 */
  626. X#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
  627. X/* STREQN is an optimised strncmp(a,b,n)==0; assumes n > 0 */
  628. X#define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0)
  629. X#define STRLEN(s) (sizeof (s) - 1)    /* s must be a char array */
  630. X#ifdef SLOW
  631. X#define INDEX(src, chr, dest) (dest) = index(src, chr)
  632. Xchar *index();
  633. X#else
  634. X#define INDEX(src, chr, dest) \
  635. X    for ((dest) = (src); *(dest) != '\0' && *(dest) != (chr); ++(dest)) \
  636. X        ; \
  637. X    if (*(dest) == '\0') \
  638. X        (dest) = NULL        /* N.B.: missing semi-colon */
  639. X#endif
  640. X
  641. X#define YES 1
  642. X#define NO 0
  643. X
  644. X/* signal types (mostly for Suns): tailor to suite local tastes */
  645. X#ifdef sun
  646. Xtypedef int (*sigret_t)();
  647. Xtypedef void (*sigarg_t)();
  648. X#else
  649. Xtypedef int (*sigret_t)();
  650. Xtypedef int (*sigarg_t)();
  651. X#endif
  652. X
  653. X/* imports from news */
  654. Xextern int remote;
  655. Xextern char *progname;
  656. Xextern FILE *fopenclex(), *fopenwclex();    /* open w close-on-exec */
  657. Xextern char *strsave(), *hostname(), *getwd();
  658. Xextern char *fgetmfs();            /* internal interface */
  659. X#define fgetms(fp) fgetmfs(fp, 0)    /* unbounded read */
  660. X#define cfgetms(fp) fgetmfs(fp, 1)    /* unbounded read with continuation */
  661. X
  662. X/* imports from libc */
  663. Xextern char *strcpy(), *strcat(), *strncpy(), *strncat();    /* strings.h */
  664. Xextern char *index(), *rindex();    /* strings.h */
  665. Xextern FILE *popen();            /* stdio.h */
  666. Xextern char *sprintf();            /* stdio.h */
  667. Xextern struct passwd *getpwnam();    /* pwd.h */
  668. Xextern struct group *getgrnam();    /* grp.h */
  669. Xextern time_t time();            /* sys/times.h? */
  670. Xextern char *ctime();            /* sys/timeb.h? */
  671. Xextern long atol();
  672. Xextern char *malloc(), *realloc();
  673. Xextern char *emalloc();
  674. Xextern char *mktemp();
  675. Xextern char *getenv();
  676. END_OF_FILE
  677. if test 2826 -ne `wc -c <'include/news.h'`; then
  678.     echo shar: \"'include/news.h'\" unpacked with wrong size!
  679. fi
  680. # end of 'include/news.h'
  681. fi
  682. if test -f 'lib.proto/README' -a "${1}" != "-c" ; then 
  683.   echo shar: Will not clobber existing file \"'lib.proto/README'\"
  684. else
  685. echo shar: Extracting \"'lib.proto/README'\" \(2418 characters\)
  686. sed "s/^X//" >'lib.proto/README' <<'END_OF_FILE'
  687. XThis README file is badly out of date but better than nothing.
  688. X
  689. Xactive        local, newsgroups, highest (& lowest) article #s, (y/n/m flag)
  690. Xanne.jones    link to mary.brown
  691. Xarbitron    local, shell script, run monthly to generate readership survey
  692. Xbatch        binary, generates outgoing news batches
  693. Xbatcher        local, shell script, invoke batch
  694. Xcaesar        binary, caesar cypher, used by readnews
  695. Xcompress    shell script, invokes the real compress & fiddles exit status
  696. Xcontrol        local, directory of shell scripts invoked by control messages
  697. Xcvt.hist    converts old 3-field history file to new 4-field history file
  698. Xerrlog        stderr of realinews, should be zero length; if not, read it
  699. Xexpire        binary, removes old articles
  700. Xexplist        local, tells expire what criteria to use
  701. Xgngp        g/newsgroup-pattern/p, used by inews
  702. Xhelp        readnews help file
  703. Xhistdups    awk file, used by mkhistory
  704. Xhistinfo    binary, used by mkhistory
  705. Xhistory        local, ascii history file, used by realinews & expire
  706. Xhistory.dir    local, dbm(3) history file bits
  707. Xhistory.pag    local, dbm(3) history file keys and values
  708. Xhistslash    used by mkhistory
  709. Xinews        shell script, invokes realinews without -p
  710. Xkill.groups    for future expansion
  711. Xkill.people    for future expansion
  712. Xlocalgroups    local, used by control/checkgroups
  713. Xlog        stdout of realinews, fairly boring
  714. Xmary.brown    local (can be tailored), shell script, censor used by inews
  715. Xmkdbm        regenerates dbm(3) history file from ascii one
  716. Xmkhistory    regenerates history file from articles (in /usr/spool/news)
  717. Xmodroutes    local, routes to backbones for various mod groups
  718. Xnewshist    binary, looks up history entry by message-id
  719. Xnewsreply    local, shell script, generate mail reply address from article
  720. Xnewsreply.from    domain mailer version of above
  721. Xnewsreply.path    non-domain mailer version of above
  722. Xnukehist    shell script, clears the decks for debugging
  723. Xorganisation    local, value for Organization: header generated by inews
  724. Xprof        directory of profiling results
  725. Xrealinews    binary, a lean, mean, news relayin' machine
  726. Xrecmail        binary, receive news by mail
  727. Xrecnews        binary, receive news somehow
  728. Xrn        directory, rn's private files
  729. Xrnews        shell script, invokes realinews with -p
  730. Xsendnews    shell script, mails news articles to ./uurec
  731. Xsys        local, controls distribution of articles to other sites & programs
  732. Xtest        directory, timing and test runs
  733. Xuucpmapmuncher    local, shell script, mails mod.map to someone for unwrapping
  734. Xuurec        shell script, unwraps news sent by ./sendnews
  735. END_OF_FILE
  736. if test 2418 -ne `wc -c <'lib.proto/README'`; then
  737.     echo shar: \"'lib.proto/README'\" unpacked with wrong size!
  738. fi
  739. # end of 'lib.proto/README'
  740. fi
  741. if test -f 'lib.proto/control/checkgroups' -a "${1}" != "-c" ; then 
  742.   echo shar: Will not clobber existing file \"'lib.proto/control/checkgroups'\"
  743. else
  744. echo shar: Extracting \"'lib.proto/control/checkgroups'\" \(2010 characters\)
  745. sed "s/^X//" >'lib.proto/control/checkgroups' <<'END_OF_FILE'
  746. X#! /bin/sh
  747. X: checkgroups - check active file for missing or extra newsgroups.
  748. X:    stdin must a checkgroups news article, sends mail to $NOTIFY
  749. X:    after updating $nl/newsgroups from $nl/localgroups
  750. X: v1.4 of 9/4/84, adapted to C news
  751. XPATH=/bin:/usr/bin:/usr/ucb; export PATH
  752. XNEWSCTL=${NEWSCTL-/usr/lib/news}; export NEWSCTL
  753. XNEWSBIN=${NEWSBIN-/usr/lib/newsbin}; export NEWSBIN
  754. XNEWSARTS=${NEWSARTS-/usr/spool/news}; export NEWSARTS
  755. XNOTIFY=usenet
  756. X
  757. X# generate newsgroups from localgroups & stdin
  758. Xcp $NEWSCTL/localgroups $NEWSCTL/newsgroups
  759. Xsed '1,/^$/d' >>$NEWSCTL/newsgroups    # behead the article (snuff headers)
  760. X
  761. X# generate list of approved newsgroups from $nl/newsgroups
  762. Xecho junk >/tmp/$$a
  763. Xecho control >>/tmp/$$a
  764. X# [^.]*\. in next two egreps was net.|mod.|fa., which is inadequate - geoff
  765. Xsed 's/[ \    ].*//' $NEWSCTL/newsgroups |
  766. X    egrep "^([^.]*\.|general)" >>/tmp/$$a
  767. Xsort -u /tmp/$$a -o /tmp/$$a
  768. X
  769. X# generate list of locally-present newsgroups from $nl/active
  770. Xegrep "^([^.]*\.|general|junk|control)" $NEWSCTL/active |
  771. X    sed 's/ .*//' | sort  -u >/tmp/$$b
  772. X
  773. X# compare 'em & note differences
  774. Xcomm -13 /tmp/$$a /tmp/$$b >/tmp/$$remove
  775. Xcomm -23 /tmp/$$a /tmp/$$b >/tmp/$$add
  776. X
  777. Xif test -s /tmp/$$remove; then
  778. X    echo "The following newsgroups are not valid and should be removed."
  779. X    sed "s/^/    /" /tmp/$$remove
  780. X    echo ""
  781. X    echo "You can do this by executing the command:"
  782. X    echo "    $NEWSCTL/control/rmgroup \\"
  783. X    sed 's;.*;        & \\;' /tmp/$$remove
  784. X    echo ""
  785. Xfi 2>&1 >/tmp/$$out
  786. X
  787. Xif test -s /tmp/$$add; then
  788. X    echo "The following newsgroups were missing." # "and were added."
  789. X    sed "s/^/    /" /tmp/$$add
  790. X    echo ""
  791. X
  792. X#    for i in `cat /tmp/$$add`
  793. X#    do
  794. X# *** "Subject: cmsg " is a hideous botch of a kludge-hack; avoid it!
  795. X#        inews -h <<!
  796. X#Control: newgroup $i
  797. X#Newsgroups: control
  798. X#Subject: newgroup $i
  799. X#Distribution: general
  800. X#
  801. X#Create $i locally.
  802. X#!
  803. X#    done
  804. X
  805. Xfi 2>&1 >>/tmp/$$out
  806. X
  807. Xif test -s /tmp/$$out; then
  808. X    (echo "Subject: Problems with your active file"; echo "";
  809. X     cat /tmp/$$out) | mail $NOTIFY
  810. Xfi
  811. X
  812. Xrm -f /tmp/$$*        # clean up temporaries
  813. END_OF_FILE
  814. if test 2010 -ne `wc -c <'lib.proto/control/checkgroups'`; then
  815.     echo shar: \"'lib.proto/control/checkgroups'\" unpacked with wrong size!
  816. fi
  817. # end of 'lib.proto/control/checkgroups'
  818. fi
  819. if test -f 'libc/fgetmfs.c' -a "${1}" != "-c" ; then 
  820.   echo shar: Will not clobber existing file \"'libc/fgetmfs.c'\"
  821. else
  822. echo shar: Extracting \"'libc/fgetmfs.c'\" \(2122 characters\)
  823. sed "s/^X//" >'libc/fgetmfs.c' <<'END_OF_FILE'
  824. X/*
  825. X * fgetmfs - read an arbitrarily long, possibly continued line;
  826. X * return a pointer to it, in malloced memory.
  827. X */
  828. X
  829. X#include <stdio.h>
  830. X#include <ctype.h>
  831. X#include <sys/types.h>
  832. X#include <fgetmfs.h>
  833. X
  834. X/* One could make these arguments, with defaults. */
  835. X#define INITLN 90        /* initial allocation per line */
  836. X#define GROWLN 200        /* additional allocation size */
  837. X
  838. X/* imports from libc */
  839. Xchar *malloc(), *realloc(), *rindex();
  840. X
  841. Xchar *
  842. Xfgetmfs(fp, cont)        /* fget malloced, flagged string */
  843. XFILE *fp;
  844. Xint cont;            /* honour \ continuations? */
  845. X{
  846. X    register unsigned sz;
  847. X    register char *line;
  848. X    register char *segment;
  849. X    register char *morep;
  850. X    register int another = 0;
  851. X
  852. X    /* allocate room for an initial segment of a line */
  853. X    sz = INITLN;
  854. X    line = malloc(sz);
  855. X    if (line == NULL)
  856. X        return NULL;        /* no memory, can't go on */
  857. X    segment = line;
  858. X    morep = line + sz - 2;
  859. X    do {
  860. X        register char *nlp;
  861. X
  862. X        /* read the first segment of a line */
  863. X        *morep = '\0';            /* mark end of segment */
  864. X        if (fgets(segment, (int)sz-(segment-line), fp) == NULL) {
  865. X            free(line);        /* EOF: give up */
  866. X            return NULL;
  867. X        }
  868. X        while (*morep != '\0' && *morep != '\n') {    /* line didn't fit */
  869. X            /* extend the allocation */
  870. X            sz += GROWLN;
  871. X            line = realloc(line, sz);
  872. X            if (line == NULL)
  873. X                return NULL;    /* no memory, can't go on */
  874. X            segment = line + sz - GROWLN - 1;
  875. X            morep = line + sz - 2;
  876. X
  877. X            /* read the next segment */
  878. X            *morep = '\0';
  879. X            if (fgets(segment, GROWLN+1, fp) == NULL) {
  880. X                free(line);    /* EOF: give up */
  881. X                return NULL;
  882. X            }
  883. X        }
  884. X
  885. X        /* got a whole line: is it to be continued? */
  886. X        if (cont && (nlp = rindex(line, '\n')) != NULL &&
  887. X            nlp > line && *--nlp == '\\') {
  888. X            *nlp = '\0';        /* delete "\\\n" */
  889. X            segment = nlp;
  890. X            another = 1;        /* read next line */
  891. X                if (cont == CONT_NOSPC) {
  892. X                register int c;
  893. X
  894. X                /* discard leading whitespace */
  895. X                while ((c = getc(fp)) != EOF && c != '\n' &&
  896. X                   isascii(c) && isspace(c))
  897. X                    ;
  898. X                if (c != EOF)
  899. X                    (void) ungetc(c, fp);
  900. X                }
  901. X        } else
  902. X            another = 0;
  903. X    } while (another);
  904. X#ifdef pdp11
  905. X    line = realloc(line, strlen(line)+1);    /* save space */
  906. X#endif
  907. X    return line;
  908. X}
  909. END_OF_FILE
  910. if test 2122 -ne `wc -c <'libc/fgetmfs.c'`; then
  911.     echo shar: \"'libc/fgetmfs.c'\" unpacked with wrong size!
  912. fi
  913. # end of 'libc/fgetmfs.c'
  914. fi
  915. if test -f 'libc/getopt.3' -a "${1}" != "-c" ; then 
  916.   echo shar: Will not clobber existing file \"'libc/getopt.3'\"
  917. else
  918. echo shar: Extracting \"'libc/getopt.3'\" \(2755 characters\)
  919. sed "s/^X//" >'libc/getopt.3' <<'END_OF_FILE'
  920. X.TH GETOPT 3 local
  921. X.DA 25 March 1982
  922. X.SH NAME
  923. Xgetopt \- get option letter from argv
  924. X.SH SYNOPSIS
  925. X.ft B
  926. Xint getopt(argc, argv, optstring)
  927. X.br
  928. Xint argc;
  929. X.br
  930. Xchar **argv;
  931. X.br
  932. Xchar *optstring;
  933. X.sp
  934. Xextern char *optarg;
  935. X.br
  936. Xextern int optind;
  937. X.ft
  938. X.SH DESCRIPTION
  939. X.I Getopt
  940. Xreturns the next option letter in
  941. X.I argv
  942. Xthat matches a letter in
  943. X.IR optstring .
  944. X.I Optstring
  945. Xis a string of recognized option letters;
  946. Xif a letter is followed by a colon, the option is expected to have
  947. Xan argument that may or may not be separated from it by white space.
  948. X.I Optarg
  949. Xis set to point to the start of the option argument on return from
  950. X.IR getopt .
  951. X.PP
  952. X.I Getopt
  953. Xplaces in
  954. X.I optind
  955. Xthe
  956. X.I argv
  957. Xindex of the next argument to be processed.
  958. XBecause
  959. X.I optind
  960. Xis external, it is normally initialized to zero automatically
  961. Xbefore the first call to 
  962. X.IR getopt .
  963. X.PP
  964. XWhen all options have been processed (i.e., up to the first
  965. Xnon-option argument),
  966. X.I getopt
  967. Xreturns
  968. X.BR EOF .
  969. XThe special option
  970. X.B \-\-
  971. Xmay be used to delimit the end of the options;
  972. X.B EOF
  973. Xwill be returned, and
  974. X.B \-\-
  975. Xwill be skipped.
  976. X.SH SEE ALSO
  977. Xgetopt(1)
  978. X.SH DIAGNOSTICS
  979. X.I Getopt
  980. Xprints an error message on
  981. X.I stderr
  982. Xand returns a question mark
  983. X.RB ( ? )
  984. Xwhen it encounters an option letter not included in
  985. X.IR optstring .
  986. X.SH EXAMPLE
  987. XThe following code fragment shows how one might process the arguments
  988. Xfor a command that can take the mutually exclusive options
  989. X.B a
  990. Xand
  991. X.BR b ,
  992. Xand the options
  993. X.B f
  994. Xand
  995. X.BR o ,
  996. Xboth of which require arguments:
  997. X.PP
  998. X.RS
  999. X.nf
  1000. Xmain(argc, argv)
  1001. Xint argc;
  1002. Xchar **argv;
  1003. X{
  1004. X    int c;
  1005. X    extern int optind;
  1006. X    extern char *optarg;
  1007. X    \&.
  1008. X    \&.
  1009. X    \&.
  1010. X    while ((c = getopt(argc, argv, "abf:o:")) != EOF)
  1011. X        switch (c) {
  1012. X        case 'a':
  1013. X            if (bflg)
  1014. X                errflg++;
  1015. X            else
  1016. X                aflg++;
  1017. X            break;
  1018. X        case 'b':
  1019. X            if (aflg)
  1020. X                errflg++;
  1021. X            else
  1022. X                bproc();
  1023. X            break;
  1024. X        case 'f':
  1025. X            ifile = optarg;
  1026. X            break;
  1027. X        case 'o':
  1028. X            ofile = optarg;
  1029. X            break;
  1030. X        case '?':
  1031. X        default:
  1032. X            errflg++;
  1033. X            break;
  1034. X        }
  1035. X    if (errflg) {
  1036. X        fprintf(stderr, "Usage: ...");
  1037. X        exit(2);
  1038. X    }
  1039. X    for (; optind < argc; optind++) {
  1040. X        \&.
  1041. X        \&.
  1042. X        \&.
  1043. X    }
  1044. X    \&.
  1045. X    \&.
  1046. X    \&.
  1047. X}
  1048. X.RE
  1049. X.PP
  1050. XA template similar to this can be found in
  1051. X.IR /usr/pub/template.c .
  1052. X.SH HISTORY
  1053. XWritten by Henry Spencer, working from a Bell Labs manual page.
  1054. XBehavior believed identical to the Bell version.
  1055. X.SH BUGS
  1056. XIt is not obvious how
  1057. X`\-'
  1058. Xstanding alone should be treated;  this version treats it as
  1059. Xa non-option argument, which is not always right.
  1060. X.PP
  1061. XOption arguments are allowed to begin with `\-';
  1062. Xthis is reasonable but reduces the amount of error checking possible.
  1063. X.PP
  1064. X.I Getopt
  1065. Xis quite flexible but the obvious price must be paid:  there is much
  1066. Xit could do that it doesn't, like
  1067. Xchecking mutually exclusive options, checking type of
  1068. Xoption arguments, etc.
  1069. END_OF_FILE
  1070. if test 2755 -ne `wc -c <'libc/getopt.3'`; then
  1071.     echo shar: \"'libc/getopt.3'\" unpacked with wrong size!
  1072. fi
  1073. # end of 'libc/getopt.3'
  1074. fi
  1075. if test -f 'libc/stdio.fast/fgets.c' -a "${1}" != "-c" ; then 
  1076.   echo shar: Will not clobber existing file \"'libc/stdio.fast/fgets.c'\"
  1077. else
  1078. echo shar: Extracting \"'libc/stdio.fast/fgets.c'\" \(2693 characters\)
  1079. sed "s/^X//" >'libc/stdio.fast/fgets.c' <<'END_OF_FILE'
  1080. X#include <stdio.h>
  1081. X#include "memcpy.h"
  1082. X
  1083. X#define THRESHOLD 12            /* memcpy vs in-line threshold */
  1084. X
  1085. Xchar *
  1086. Xfgets(s, lim, fp)            /* optimised version */
  1087. Xchar *s;
  1088. Xint lim;
  1089. Xregister FILE *fp;
  1090. X{
  1091. X    char *rets = s;            /* normal return by default */
  1092. X
  1093. X    --lim;                /* leave room for terminating null */
  1094. X    while (lim > 0) {        /* room left in s */
  1095. X        int origbytesleft;
  1096. X        char *nlp = NULL;    /* points at newline */
  1097. X
  1098. X        /*
  1099. X         * Find next newline (if any) by running through the
  1100. X         * stdio buffer until it runs out or a newline is seen.
  1101. X         * This dominates the running time for long lines.
  1102. X         */
  1103. X        {
  1104. X            register char *bp = fp->_ptr;
  1105. X            register int loops;
  1106. X            /* bytes to the end of s or the stdio buffer */
  1107. X            register int bytesleft = fp->_cnt;    /* to EOB */
  1108. X
  1109. X            if (bytesleft > lim)    /* buffer longer than s */
  1110. X                bytesleft = lim; /* only copy to s's end */
  1111. X            origbytesleft = bytesleft;
  1112. X
  1113. X            /*
  1114. X             * This code uses Duff's Device (tm Tom Duff)
  1115. X             * to unroll the newline recogniser:
  1116. X             * for (++bytesleft; --bytesleft > 0; )
  1117. X             *    if (*bp++ == '\n') {
  1118. X             *        nlp = bp;    # NB points after \n
  1119. X             *        break;
  1120. X             *    }
  1121. X             * Sorry the code is so ugly.
  1122. X             */
  1123. X            if (bytesleft > 0) {
  1124. X                /* TODO: #ifdef for non-twos-complement mchs */
  1125. X                loops = (bytesleft+8-1) >> 3;    /* /8 round up */
  1126. X
  1127. X                switch (bytesleft&(8-1)) {    /* %8 */
  1128. X                case 0: do {
  1129. X#define SPOTNL if (*bp++ == '\n') { nlp = bp; break; }
  1130. X                        SPOTNL;
  1131. X                    case 7:    SPOTNL;
  1132. X                    case 6:    SPOTNL;
  1133. X                    case 5:    SPOTNL;
  1134. X                    case 4:    SPOTNL;
  1135. X                    case 3:    SPOTNL;
  1136. X                    case 2:    SPOTNL;
  1137. X                    case 1:    SPOTNL;
  1138. X                    } while (--loops > 0);
  1139. X                }
  1140. X            }
  1141. X        }
  1142. X        /*
  1143. X         * If no newline was seen, copy remaining bytes from stdio
  1144. X         * buffer; else copy up to and including the newline.
  1145. X         * Adjust counts, then copy the bytes & adjust pointers.
  1146. X         * This dominates the running time for short lines.
  1147. X         */
  1148. X        {
  1149. X            register int copy;
  1150. X
  1151. X            if (nlp == NULL)
  1152. X                copy = origbytesleft;
  1153. X            else
  1154. X                copy = nlp - fp->_ptr;
  1155. X            lim -= copy;
  1156. X            fp->_cnt -= copy;
  1157. X            if (copy < THRESHOLD) {
  1158. X                register char *rs = s, *bp = fp->_ptr;
  1159. X
  1160. X                for (++copy; --copy > 0; )
  1161. X                    *rs++ = *bp++;
  1162. X                s = rs;
  1163. X                fp->_ptr = bp;
  1164. X            } else {
  1165. X                memcpy(s, fp->_ptr, copy);
  1166. X                s += copy;
  1167. X                fp->_ptr += copy;
  1168. X            }
  1169. X        }
  1170. X        /*
  1171. X         * Quit if we saw a newline or "s" is full,
  1172. X         * else refill the stdio buffer and go again.
  1173. X         */
  1174. X        if (nlp != NULL || lim <= 0)
  1175. X            break;
  1176. X        else if (fp->_cnt <= 0) {        /* buffer empty */
  1177. X            register int c = getc(fp);    /* fill buffer */
  1178. X
  1179. X            if (c == EOF) {
  1180. X                if (s == rets)        /* s is empty */
  1181. X                    rets = NULL;
  1182. X                break;            /* EOF return */
  1183. X            } else {
  1184. X                if ((*s++ = c) == '\n')
  1185. X                    break;        /* newline return */
  1186. X                --lim;
  1187. X            }
  1188. X        }
  1189. X    }
  1190. X    *s = '\0';    /* terminate s */
  1191. X    return rets;
  1192. X}
  1193. END_OF_FILE
  1194. if test 2693 -ne `wc -c <'libc/stdio.fast/fgets.c'`; then
  1195.     echo shar: \"'libc/stdio.fast/fgets.c'\" unpacked with wrong size!
  1196. fi
  1197. # end of 'libc/stdio.fast/fgets.c'
  1198. fi
  1199. if test -f 'libc/stdio.fast/rdwr.c' -a "${1}" != "-c" ; then 
  1200.   echo shar: Will not clobber existing file \"'libc/stdio.fast/rdwr.c'\"
  1201. else
  1202. echo shar: Extracting \"'libc/stdio.fast/rdwr.c'\" \(2257 characters\)
  1203. sed "s/^X//" >'libc/stdio.fast/rdwr.c' <<'END_OF_FILE'
  1204. X/*
  1205. X * fread and fwrite (optimised version)
  1206. X * TODO: i/o to/from the user's buffer directly if the transfer is long enough.
  1207. X *    If there's a block-aligned block (or more) in the middle, do it directly.
  1208. X */
  1209. X
  1210. X#include <stdio.h>
  1211. X#include "memcpy.h"
  1212. X
  1213. X#define THRESHOLD 12            /* memcpy vs in-line threshold */
  1214. X
  1215. Xtypedef unsigned char putc_t;        /* cast putc args to this type */
  1216. X
  1217. Xint
  1218. Xfread(ptr, size, count, fp)
  1219. Xchar *ptr;
  1220. Xint size, count;
  1221. Xregister FILE *fp;
  1222. X{
  1223. X    register unsigned bytes = count * size;
  1224. X    unsigned origbytes = bytes;
  1225. X
  1226. X    while (bytes > 0) {    /* bytes still to be read */
  1227. X        {
  1228. X            /* all of bytes in buffer */
  1229. X            register int copy = fp->_cnt;
  1230. X
  1231. X            if (copy > bytes)    /* buffer longer than ptr */
  1232. X                copy = bytes;    /* only fill ptr */
  1233. X            bytes -= copy;    /* adjust to reflect next loop */
  1234. X            fp->_cnt -= copy;
  1235. X            if (copy < THRESHOLD) {
  1236. X                register char *rptr = ptr, *bp = fp->_ptr;
  1237. X
  1238. X                for (++copy; --copy > 0; )
  1239. X                    *rptr++ = *bp++;
  1240. X                ptr = rptr;
  1241. X                fp->_ptr = bp;
  1242. X            } else {
  1243. X                memcpy(ptr, fp->_ptr, copy);
  1244. X                ptr += copy;
  1245. X                fp->_ptr += copy;
  1246. X            }
  1247. X        }
  1248. X        if (bytes > 0) {    /* more to read, but buffer is empty */
  1249. X            register int c = getc(fp);    /* refill buffer */
  1250. X
  1251. X            if (c == EOF)
  1252. X                break;
  1253. X            else {
  1254. X                *ptr++ = c;
  1255. X                --bytes;
  1256. X            }
  1257. X        }
  1258. X    }
  1259. X    if (size == 0)
  1260. X        return count;            /* or 0 */
  1261. X    else
  1262. X        return (origbytes - bytes) / size;
  1263. X}
  1264. X
  1265. Xint
  1266. Xfwrite(ptr, size, count, fp)
  1267. Xchar *ptr;
  1268. Xint size, count;
  1269. Xregister FILE *fp;
  1270. X{
  1271. X    register unsigned bytes = count * size;
  1272. X    unsigned origbytes = bytes;
  1273. X
  1274. X    while (bytes > 0) {    /* bytes still to be written */
  1275. X        {
  1276. X            register int copy = fp->_cnt;
  1277. X
  1278. X            if (copy > bytes)    /* buffer longer than ptr */
  1279. X                copy = bytes;    /* only empty ptr */
  1280. X            bytes -= copy;    /* adjust to reflect next loop */
  1281. X            fp->_cnt -= copy;
  1282. X            if (copy < THRESHOLD) {
  1283. X                register char *rptr = ptr, *bp = fp->_ptr;
  1284. X
  1285. X                for (++copy; --copy > 0; )
  1286. X                    *bp++ = *rptr++;
  1287. X                ptr = rptr;
  1288. X                fp->_ptr = bp;
  1289. X            } else {
  1290. X                memcpy(fp->_ptr, ptr, copy);
  1291. X                ptr += copy;
  1292. X                fp->_ptr += copy;
  1293. X            }
  1294. X        }
  1295. X        if (bytes > 0)    /* more to write, but buffer is full */
  1296. X            if (putc((putc_t)*ptr, fp) == EOF) /* flush buffer */
  1297. X                break;
  1298. X            else {
  1299. X                ptr++;
  1300. X                --bytes;
  1301. X            }
  1302. X    }
  1303. X    if (size == 0)
  1304. X        return count;            /* or 0 */
  1305. X    else
  1306. X        return (origbytes - bytes) / size;
  1307. X}
  1308. END_OF_FILE
  1309. if test 2257 -ne `wc -c <'libc/stdio.fast/rdwr.c'`; then
  1310.     echo shar: \"'libc/stdio.fast/rdwr.c'\" unpacked with wrong size!
  1311. fi
  1312. # end of 'libc/stdio.fast/rdwr.c'
  1313. fi
  1314. if test -f 'libc/strings/Makefile' -a "${1}" != "-c" ; then 
  1315.   echo shar: Will not clobber existing file \"'libc/strings/Makefile'\"
  1316. else
  1317. echo shar: Extracting \"'libc/strings/Makefile'\" \(2552 characters\)
  1318. sed "s/^X//" >'libc/strings/Makefile' <<'END_OF_FILE'
  1319. X# String library.
  1320. X
  1321. X# Configuration settings:  how should "size_t", "void *", "const" be written?
  1322. X# "size_t" is what's needed to hold the result of sizeof; beware of problems
  1323. X# with compatibility here, because X3J11 uses this for e.g. the third
  1324. X# argument of strncpy() as well.  You may need to make it "int" even if
  1325. X# this is a lie.  "void *" is the generic pointer type, "char *" in most
  1326. X# existing implementations.  "const" is the keyword marking read-only
  1327. X# variables and parameters, unimplemented in most existing implementations.
  1328. X# These things need to be defined this way because they must be fitted into
  1329. X# both the .h files and the .c files; see the make instructions for string.h
  1330. X# farther down.
  1331. XSIZET = int
  1332. XVOIDSTAR = char *
  1333. XLVOIDSTAR = char*    # Lint shell file has problems with * alone.  Barf.
  1334. XCONST = 
  1335. X
  1336. XCONF = -DSIZET=$(SIZET) -DVOIDSTAR='$(VOIDSTAR)' -DCONST='$(CONST)'
  1337. XLCONF = -DSIZET=$(SIZET) -DVOIDSTAR='$(LVOIDSTAR)' -DCONST='$(CONST)'
  1338. X
  1339. X# Things you might want to put in CFLAGS or LINTFLAGS.
  1340. X# -DCHARBITS=0377        Required if compiler lacks "unsigned char".
  1341. X# -Dvoid=int            Required if compiler lacks "void".
  1342. X# -DUNIXERR            Unix-like errno stuff, can test strerror().
  1343. X# -DBERKERR            Like UNIXERR but for Berklix (4BSD).
  1344. X# -I.                string.h from here, not /usr/include.
  1345. X
  1346. XCFLAGS = -O $(CONF) -DUNIXERR -I.
  1347. XLINTFLAGS = -hpan $(LCONF) -DUNIXERR -Dvoid=int -DCHARBITS=0377 -I.
  1348. XLDFLAGS = -i
  1349. X
  1350. X# Name lists.
  1351. XSTRING = index.o rindex.o strcat.o strchr.o strcmp.o strcpy.o strcspn.o \
  1352. X    strlen.o strncat.o strncmp.o strncpy.o strpbrk.o strrchr.o strspn.o \
  1353. X    strtok.o strstr.o memcpy.o memccpy.o memcmp.o memchr.o memset.o \
  1354. X    bcopy.o bcmp.o bzero.o strerror.o
  1355. XCSTRING = index.c rindex.c strcat.c strchr.c strcmp.c strcpy.c strcspn.c \
  1356. X    strlen.c strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strspn.c \
  1357. X    strtok.c strstr.c memcpy.c memccpy.c memcmp.c memchr.c memset.c \
  1358. X    bcopy.c bcmp.c bzero.c strerror.c
  1359. XDTR = README Makefile $(CSTRING) tester.c string.h.proto
  1360. X
  1361. X# Locations, for installation (somewhat system-dependent).
  1362. XDEST=..
  1363. X
  1364. Xtester.o:    string.h
  1365. X
  1366. Xmv:    $(STRING)
  1367. X    mv $(STRING) $(DEST)
  1368. X
  1369. Xr:    tester
  1370. X    @echo 'No news is good news.  Note: strerror() test is VERY system-dependent.'
  1371. X    tester
  1372. X
  1373. Xtester:    tester.o $(STRING)
  1374. X    cc $(LDFLAGS) tester.o $(STRING) -o tester
  1375. X
  1376. Xstring.h:    string.h.proto
  1377. X    sed 's/SIZET/$(SIZET)/g;s/VOIDSTAR /$(VOIDSTAR)/g' string.h.proto >string.h
  1378. X
  1379. Xmemory.h:    string.h
  1380. X    egrep mem string.h >memory.h
  1381. X
  1382. Xlint:    string.h
  1383. X    lint $(LINTFLAGS) tester.c $(CSTRING)
  1384. X
  1385. Xclean:
  1386. X    rm -f tester a.out *.o string.h memory.h dtr
  1387. X
  1388. Xdtr:    $(DTR)
  1389. X    makedtr $(DTR) >dtr
  1390. END_OF_FILE
  1391. if test 2552 -ne `wc -c <'libc/strings/Makefile'`; then
  1392.     echo shar: \"'libc/strings/Makefile'\" unpacked with wrong size!
  1393. fi
  1394. # end of 'libc/strings/Makefile'
  1395. fi
  1396. if test -f 'libc/strings/README' -a "${1}" != "-c" ; then 
  1397.   echo shar: Will not clobber existing file \"'libc/strings/README'\"
  1398. else
  1399. echo shar: Extracting \"'libc/strings/README'\" \(2642 characters\)
  1400. sed "s/^X//" >'libc/strings/README' <<'END_OF_FILE'
  1401. XThis is a public-domain reimplementation of string(3) and friends, notably
  1402. Xmemory(3) and bstring(3) (except ffs).  Not derived from licensed software.
  1403. XThis code may be used on any computer system for any purpose by anyone.
  1404. X
  1405. XRelative to my old net.sources posting, this one adds some functions and
  1406. Xfixes one or two obscure bugs.  There has been another string library
  1407. Xposted in recent times, with many more functions; I haven't inspected it
  1408. Xand can't comment on its relationship to mine.  Alas, the manual pages
  1409. Xfor this stuff are copyright by various people other than me, so I can't
  1410. Xinclude them.  See your local Unix manuals.
  1411. X
  1412. XThis distribution implements precisely the union of the string functions
  1413. Xof the SVID, 4BSD, X3J11, and V7.  Included is a large test program that
  1414. Xexercises everything quite thoroughly.  (Note that some existing libraries,
  1415. Xincluding e.g. V7, flunk one or more of these tests.)
  1416. X
  1417. XIn the event of conflict between the definitions from various places, the
  1418. Xnewer or more portable one is chosen.  That is, X3J11 overrules the SVID,
  1419. Xwhich in turn overrules older Unixes.
  1420. X
  1421. XThe code is written for maximal portability.  Some efficiency has been
  1422. Xsacrificed in the cause of meticulously avoiding possible portability
  1423. Xproblems.  For example, this code never assumes that a pointer can be
  1424. Xmoved past the end of an array and then backed up.  Many of these functions
  1425. Xcan be implemented more efficiently if machine-dependent assumptions are
  1426. Xmade; memcpy is a particular glaring case.
  1427. X
  1428. XSimplistically:  put this stuff into a source directory, inspect Makefile
  1429. Xfor compilation options that need changing to suit your local environment,
  1430. Xand then do "make r".  This compiles the functions and the test program and
  1431. Xruns the tests.  If there are no complaints, put string.h in /usr/include
  1432. X(you may also want to "make memory.h" and put it in /usr/include) and add
  1433. Xthe functions (*.o except for tester.o) to your C library.  The internal
  1434. Xinterdependencies are:
  1435. X
  1436. X    index    needs    strchr
  1437. X    rindex    needs    strrchr
  1438. X    bcopy    needs    memcpy
  1439. X    bcmp    needs    memcmp
  1440. X    bzero    needs    memset
  1441. X
  1442. XI haven't included an implementation of Berkeley's ffs function partly
  1443. Xbecause it's not trivial to do in a portable way, and partly because I
  1444. Xdon't really see it as a string function.
  1445. X
  1446. XA weakness in the tester program is that it uses quite short strings for
  1447. Xeverything, and pays no real attention to alignment issues.  Optimized
  1448. Ximplementations of things like memcpy would need a more elaborate set of
  1449. Xtest cases to put them through their full paces.
  1450. X
  1451. X                Henry Spencer @ U of Toronto Zoology
  1452. X                {allegra,ihnp4,decvax,pyramid}!utzoo!henry
  1453. X                Wed Jun 25 19:21:34 EDT 1986
  1454. END_OF_FILE
  1455. if test 2642 -ne `wc -c <'libc/strings/README'`; then
  1456.     echo shar: \"'libc/strings/README'\" unpacked with wrong size!
  1457. fi
  1458. # end of 'libc/strings/README'
  1459. fi
  1460. if test -f 'newsbin.proto/control/checkgroups' -a "${1}" != "-c" ; then 
  1461.   echo shar: Will not clobber existing file \"'newsbin.proto/control/checkgroups'\"
  1462. else
  1463. echo shar: Extracting \"'newsbin.proto/control/checkgroups'\" \(2010 characters\)
  1464. sed "s/^X//" >'newsbin.proto/control/checkgroups' <<'END_OF_FILE'
  1465. X#! /bin/sh
  1466. X: checkgroups - check active file for missing or extra newsgroups.
  1467. X:    stdin must a checkgroups news article, sends mail to $NOTIFY
  1468. X:    after updating $nl/newsgroups from $nl/localgroups
  1469. X: v1.4 of 9/4/84, adapted to C news
  1470. XPATH=/bin:/usr/bin:/usr/ucb; export PATH
  1471. XNEWSCTL=${NEWSCTL-/usr/lib/news}; export NEWSCTL
  1472. XNEWSBIN=${NEWSBIN-/usr/lib/newsbin}; export NEWSBIN
  1473. XNEWSARTS=${NEWSARTS-/usr/spool/news}; export NEWSARTS
  1474. XNOTIFY=usenet
  1475. X
  1476. X# generate newsgroups from localgroups & stdin
  1477. Xcp $NEWSCTL/localgroups $NEWSCTL/newsgroups
  1478. Xsed '1,/^$/d' >>$NEWSCTL/newsgroups    # behead the article (snuff headers)
  1479. X
  1480. X# generate list of approved newsgroups from $nl/newsgroups
  1481. Xecho junk >/tmp/$$a
  1482. Xecho control >>/tmp/$$a
  1483. X# [^.]*\. in next two egreps was net.|mod.|fa., which is inadequate - geoff
  1484. Xsed 's/[ \    ].*//' $NEWSCTL/newsgroups |
  1485. X    egrep "^([^.]*\.|general)" >>/tmp/$$a
  1486. Xsort -u /tmp/$$a -o /tmp/$$a
  1487. X
  1488. X# generate list of locally-present newsgroups from $nl/active
  1489. Xegrep "^([^.]*\.|general|junk|control)" $NEWSCTL/active |
  1490. X    sed 's/ .*//' | sort  -u >/tmp/$$b
  1491. X
  1492. X# compare 'em & note differences
  1493. Xcomm -13 /tmp/$$a /tmp/$$b >/tmp/$$remove
  1494. Xcomm -23 /tmp/$$a /tmp/$$b >/tmp/$$add
  1495. X
  1496. Xif test -s /tmp/$$remove; then
  1497. X    echo "The following newsgroups are not valid and should be removed."
  1498. X    sed "s/^/    /" /tmp/$$remove
  1499. X    echo ""
  1500. X    echo "You can do this by executing the command:"
  1501. X    echo "    $NEWSCTL/control/rmgroup \\"
  1502. X    sed 's;.*;        & \\;' /tmp/$$remove
  1503. X    echo ""
  1504. Xfi 2>&1 >/tmp/$$out
  1505. X
  1506. Xif test -s /tmp/$$add; then
  1507. X    echo "The following newsgroups were missing." # "and were added."
  1508. X    sed "s/^/    /" /tmp/$$add
  1509. X    echo ""
  1510. X
  1511. X#    for i in `cat /tmp/$$add`
  1512. X#    do
  1513. X# *** "Subject: cmsg " is a hideous botch of a kludge-hack; avoid it!
  1514. X#        inews -h <<!
  1515. X#Control: newgroup $i
  1516. X#Newsgroups: control
  1517. X#Subject: newgroup $i
  1518. X#Distribution: general
  1519. X#
  1520. X#Create $i locally.
  1521. X#!
  1522. X#    done
  1523. X
  1524. Xfi 2>&1 >>/tmp/$$out
  1525. X
  1526. Xif test -s /tmp/$$out; then
  1527. X    (echo "Subject: Problems with your active file"; echo "";
  1528. X     cat /tmp/$$out) | mail $NOTIFY
  1529. Xfi
  1530. X
  1531. Xrm -f /tmp/$$*        # clean up temporaries
  1532. END_OF_FILE
  1533. if test 2010 -ne `wc -c <'newsbin.proto/control/checkgroups'`; then
  1534.     echo shar: \"'newsbin.proto/control/checkgroups'\" unpacked with wrong size!
  1535. fi
  1536. # end of 'newsbin.proto/control/checkgroups'
  1537. fi
  1538. if test -f 'rnews/setnewsids/makefile' -a "${1}" != "-c" ; then 
  1539.   echo shar: Will not clobber existing file \"'rnews/setnewsids/makefile'\"
  1540. else
  1541. echo shar: Extracting \"'rnews/setnewsids/makefile'\" \(2159 characters\)
  1542. sed "s/^X//" >'rnews/setnewsids/makefile' <<'END_OF_FILE'
  1543. X# makefile for C news setnewsids
  1544. X
  1545. X# define NOSTOREVAL if your dbm store() returns no value (as in orig. v7)
  1546. X# -I. for fcntl.h if present
  1547. XDEFINES= -I../../include -I../. -DSTATIC=
  1548. X# -Dvoid=int            # if your compiler doesn't understand void's
  1549. X# -DMAXLONG=017777777777L    # if your compiler lacks "unsigned long" type
  1550. X# -Dindex=strchr -Drindex=strrchr    # if not on (System III or V or PWB)
  1551. X
  1552. XCFLAGS=-O $(DEFINES) # -pg # -Z: John Bruner's Z0MAGIC (unmapped first page)
  1553. XLIBS= ../memcpy.o ../../libcnews/*.a -ldbm ../../libc/*.a # -lstdio
  1554. XLLIBS=-llocal
  1555. XPROPTS=-l132
  1556. XP=impr -p
  1557. X
  1558. XPOSSDEPFILES=fcntl.h gethostname.c getwd.c dbm.c mkdir.c ftime.c clsexec.c memcpy.c
  1559. X# adjust next three lines for your OS; sources are links to vers/*/*.c
  1560. XDEPHDR=
  1561. XDEPSRC= clsexec.c memcpy.c zeropad.c
  1562. XDEPOBJ= clsexec.o memcpy.o zeropad.o
  1563. X
  1564. XLIBSRCS= ../../libcnews/*.c
  1565. XLIBOBJS= ../../libcnews/../libcnews.a ../../libc/../libc.a
  1566. XSRC=setnewsids.c
  1567. XOBJ=setnewsids.o
  1568. XFILES=$(SRC)
  1569. XLINT=lint
  1570. XLINTFLAGS=-haz $(DEFINES)
  1571. X
  1572. Xall: setnewsids
  1573. X
  1574. XTODO.grep: TODO
  1575. X    -egrep TODO TODO ../../include/*.h *.h *.c sh/* >$@
  1576. X    -egrep TODO ../../libc/memcpy.fast/src/*.c ../../libcnews/*.c >>$@
  1577. X
  1578. Xv7 v8 v9 usg bsd42: clean
  1579. X    for file in vers/$@/*.c; do ln $$file; done
  1580. X    @echo 'Now edit makefile DEPSRC and DEPOBJ definitions to match:'
  1581. X    @echo vers/$@/*.c | sed 's;vers/$@/;;g'
  1582. X
  1583. Xsetnewsids: $(OBJ) ../../libcnews/*.c
  1584. X    $(CC) $(CFLAGS) $(OBJ) $(LIBS) -o $@
  1585. Xlint: $(SRC)
  1586. X    $(LINT) $(LINTFLAGS) $(SRC) $(LIBS) $(LLIBS) | egrep -v ':$$'
  1587. Xlintport: $(SRC)
  1588. X    $(LINT) $(LINTFLAGS) -p $(SRC) $(LIBS) $(LLIBS)
  1589. X
  1590. Xprint: $(FILES)
  1591. X    pr $(PROPTS) $? | $P
  1592. X    touch print
  1593. Xdistr: $(FILES)
  1594. X    (echo setnewsids update of `date`; echo ""; bundle $?) | /bin/mail cnews-updates
  1595. X    touch distr
  1596. Xclean:
  1597. X    rm -f core a.out setnewsids *.o $(POSSDEPFILES)
  1598. X
  1599. X# header dependencies follow
  1600. Xsetnewsids.o: ../../include/news.h ../../include/newspaths.h
  1601. Xactive.o: ../../include/news.h
  1602. Xcontrol.o: ../../include/news.h headers.h
  1603. Xfileart.o: ../../include/news.h headers.h
  1604. Xheaders.o: ../../include/news.h headers.h
  1605. Xhistory.o: ../../include/news.h headers.h
  1606. Xhostname.o: ../../include/news.h
  1607. Xsys.o: ../../include/news.h system.h
  1608. Xtransmit.o: ../../include/news.h headers.h system.h
  1609. END_OF_FILE
  1610. if test 2159 -ne `wc -c <'rnews/setnewsids/makefile'`; then
  1611.     echo shar: \"'rnews/setnewsids/makefile'\" unpacked with wrong size!
  1612. fi
  1613. # end of 'rnews/setnewsids/makefile'
  1614. fi
  1615. if test -f 'rnews/vers/usg/dbm.c' -a "${1}" != "-c" ; then 
  1616.   echo shar: Will not clobber existing file \"'rnews/vers/usg/dbm.c'\"
  1617. else
  1618. echo shar: Extracting \"'rnews/vers/usg/dbm.c'\" \(2521 characters\)
  1619. sed "s/^X//" >'rnews/vers/usg/dbm.c' <<'END_OF_FILE'
  1620. X/*
  1621. X * Incredibly slow Uglix dbm simulation.
  1622. X */
  1623. X
  1624. X#include <stdio.h>
  1625. X#include <sys/types.h>
  1626. X#include <sys/stat.h>
  1627. X
  1628. X#define MAXFILE 140
  1629. X#define MAXLINE 1024
  1630. X
  1631. Xstatic char pagname[MAXFILE];
  1632. Xstatic FILE *db;
  1633. Xstatic int dbrdonly;
  1634. X
  1635. Xtypedef struct {
  1636. X    char *dptr;
  1637. X    int dsize;
  1638. X} datum;
  1639. X
  1640. Xdbminit(file)
  1641. Xchar *file;
  1642. X{
  1643. X    char *strcat(), *strcpy();
  1644. X
  1645. X    dbrdonly = 0;
  1646. X    strcpy(pagname, file);
  1647. X    strcat(pagname, ".pag");
  1648. X    if ((db = fopen(pagname, "r+")) == NULL) {
  1649. X        db = fopen(pagname, "r");
  1650. X        dbrdonly = 1;
  1651. X    }
  1652. X    if (db == NULL) {
  1653. X        warning("cannot open database %s\n", file);
  1654. X        return -1;
  1655. X    }
  1656. X    return 0;
  1657. X}
  1658. X
  1659. Xdatum
  1660. Xfetch(key)
  1661. Xdatum key;
  1662. X{
  1663. X    datum item;
  1664. X
  1665. X    rewind(db);
  1666. X    while (getitem(&item, db) != EOF)        /* read key */
  1667. X        if (strncmp(item.dptr, key.dptr, key.dsize) == 0)
  1668. X            if (getitem(&item, db) == EOF)    /* read data */
  1669. X                break;
  1670. X            else
  1671. X                return item;
  1672. X    /* EOF */
  1673. X    item.dptr = NULL;
  1674. X    item.dsize = 0;
  1675. X    return item;
  1676. X}
  1677. X
  1678. Xdelete(key)
  1679. Xdatum key;
  1680. X{
  1681. X    datum item;
  1682. X    FILE *temp;
  1683. X    FILE *tmpfile();
  1684. X
  1685. X    if (dbrdonly)
  1686. X        return -1;
  1687. X    temp = tmpfile();
  1688. X    if (temp == NULL)
  1689. X        return -1;
  1690. X    /* copy from db to temp, omitting key & its data */
  1691. X    rewind(db);
  1692. X    while (getitem(&item, db) != EOF)
  1693. X        if (strncmp(item.dptr, key.dptr, key.dsize) == 0) {
  1694. X            if (getitem(&item, db) == EOF)    /* toss data too */
  1695. X                return -1;
  1696. X        } else
  1697. X            if (putitem(&item, temp) == EOF)
  1698. X                return -1;
  1699. X    /* copy back from temp to db */
  1700. X    rewind(temp);
  1701. X    db = freopen(pagname, "w+", db);
  1702. X    while (getitem(&item, temp) != EOF)
  1703. X        if (putitem(&item, db) == EOF)
  1704. X            return -1;
  1705. X    return 0;
  1706. X}
  1707. X
  1708. Xstore(key, dat)
  1709. Xdatum key, dat;
  1710. X{
  1711. X    if (dbrdonly)
  1712. X        return -1;
  1713. X#ifdef REALDBM            /* else, it's only for news */
  1714. X    if (delete(key) == -1)
  1715. X        return -1;
  1716. X#endif
  1717. X    if (putitem(&key, db) == EOF || putitem(&dat, db) == EOF)
  1718. X        return -1;
  1719. X    return 0;
  1720. X}
  1721. X
  1722. Xdatum
  1723. Xfirstkey()
  1724. X{
  1725. X    datum trash;
  1726. X    datum nextkey();
  1727. X
  1728. X    rewind(db);
  1729. X    return nextkey(trash);
  1730. X}
  1731. X
  1732. Xdatum
  1733. Xnextkey(key)            /* simplistic version, ignores key */
  1734. Xdatum key;
  1735. X{
  1736. X    static datum dat;
  1737. X
  1738. X    if (getitem(&dat, db) == EOF)
  1739. X        dat.dptr = NULL;
  1740. X    return dat;
  1741. X}
  1742. X
  1743. Xstatic int
  1744. Xgetitem(datump, fp)            /* points at static storage */
  1745. Xdatum *datump;
  1746. XFILE *fp;
  1747. X{
  1748. X    static char data[MAXLINE];
  1749. X
  1750. X    if (fread((char *)&datump->dsize, sizeof datump->dsize, 1, fp) != 1)
  1751. X        return EOF;
  1752. X    datump->dptr = data;
  1753. X    if (fread(data, datump->dsize, 1, fp) != 1)
  1754. X        return EOF;
  1755. X    return 0;
  1756. X}
  1757. X
  1758. Xstatic int
  1759. Xputitem(datump, fp)
  1760. Xdatum *datump;
  1761. XFILE *fp;
  1762. X{
  1763. X    if (fwrite((char *)&datump->dsize, sizeof datump->dsize, 1, fp) != 1)
  1764. X        return EOF;
  1765. X    if (fwrite(datump->dptr, datump->dsize, 1, fp) != 1)
  1766. X        return EOF;
  1767. X    return 0;
  1768. X}
  1769. END_OF_FILE
  1770. if test 2521 -ne `wc -c <'rnews/vers/usg/dbm.c'`; then
  1771.     echo shar: \"'rnews/vers/usg/dbm.c'\" unpacked with wrong size!
  1772. fi
  1773. # end of 'rnews/vers/usg/dbm.c'
  1774. fi
  1775. echo shar: End of archive 5 \(of 14\).
  1776. ##  End of shell archive.
  1777. exit 0
  1778.